home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d26 / cattest.arc / EVALTEST.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-01  |  3KB  |  85 lines

  1. {$A+,B-,D+,E+,F-,I+,L+,N-,O-,R-,S+,V+}
  2. {$M 16384,0,655360}
  3.  
  4. USES
  5.  CRT,UTILITY,EVAL3,checkans;
  6.  
  7. CONST
  8.   fn_char_set = ['a','b','s','r','o','u','n','d',
  9.                   't','c','q','i','h','l','g','p','f','e','x'];
  10.  
  11. VAR
  12.   My_2nd_Formula,
  13.   MyFormula : STRING;
  14.   MyValue : real;
  15.   MyErrorPosition : Integer;
  16.   MyErrorType : Integer;
  17.   MyErrMsg : STRING;
  18.   Escaped : Boolean;
  19.   posvar : Integer;
  20.  
  21. BEGIN {evaltest, MAIN entry}
  22.   Randomize;
  23.   REPEAT
  24.     MyFormula := '';
  25.     ClrScr;
  26.     Our_Write(1,1,'Testing EVAL3 for numerical formulii.');
  27.     MyFormula := Read_Equation(1,25,79,'Enter the formula("?" to halt).',
  28.                   fn_char_set);
  29.     IF MyFormula[1] <> '?'
  30.       THEN
  31.         BEGIN
  32.           Evaluate(MyFormula,MyValue,MyErrorPosition,MyErrMsg);
  33.           IF MyErrorPosition <> 0
  34.             THEN Our_Write(1,2,'Error');
  35.           IF (MyErrorPosition <> 0) AND (MyErrorType = 0)
  36.             THEN
  37.               Our_Write(1,2,'not finished with expression evaluation');
  38.           WriteLn(MyValue); {This is not a string, hence writeLN}
  39.           Pause(1,25,'Press any key to continue.');
  40.         END;
  41.   UNTIL MyFormula[1] = '?';
  42.   REPEAT
  43.     MyFormula := '';
  44.     ClrScr;
  45.     Our_Write(1,1,'Testing EVAL3 for text based formulii.');
  46.     REPEAT
  47.       Our_Write(1,2,
  48.           'Enter the character to be used as a variable("?" to halt).');
  49.       ReadLn(variable);
  50.       if variable = '?' then halt;
  51.     UNTIL variable IN ['a'..'z','A'..'Z'];
  52.     uc_var := UpCase(variable);
  53.     IF uc_var = variable
  54.       THEN lc_var := Chr(Ord(variable) - Ord('A')+Ord('a'))
  55.       ELSE lc_var := variable;
  56.     MyFormula := Read_Equation(1,25,79,
  57.             'Enter the formula using '+variable+' ("?" to halt).',
  58.              fn_char_set);(*variables already included*)
  59.     IF MyFormula[1] = '?'
  60.       THEN halt;
  61.   { first lower case the string }
  62.   FOR posvar :=1 TO Length(Myformula) DO
  63.     IF (MyFormula[posvar] >= 'A') AND (MyFormula[posvar] <= 'Z')
  64.       THEN
  65.         MyFormula[posvar] := Chr(Ord(MyFormula[posvar]) + Ord('a') - Ord('A'));
  66.     Our_Write(1,4,MyFormula);
  67.     My_2nd_Formula := Read_Equation(1,25,79,'Enter the formula("?" to halt).',
  68.                       fn_char_set);(*variables already included*)
  69.     IF My_2nd_Formula[1] = '?'
  70.       THEN halt;
  71.   { first lower case the string }
  72.   FOR posvar:=1 TO Length(My_2nd_Formula) DO
  73.     IF (My_2nd_Formula[posvar] >= 'A') AND (My_2nd_Formula[posvar] <= 'Z')
  74.       THEN
  75.         MyFormula[posvar] := Chr(Ord(MyFormula[posvar]) + Ord('a') - Ord('A'));
  76.     Our_Write(1,5,My_2nd_Formula);
  77.     IF Check_Answer(MyFormula,My_2nd_Formula,0.001)
  78.       THEN
  79.         Our_Write(1,3,'Formulas are equal.')
  80.       ELSE
  81.         Our_Write(1,3,'Formulas are NOT equal.');
  82.     Pause(1,25,'Press any key to continue.');
  83.   UNTIL MyFormula[1] = '?';
  84. END.
  85.